#!/bin/bash
set -euo pipefail
BaseDir=$(cd "$(dirname "$0")"; pwd)
cd ${BaseDir}

source ./env.gitlab
echo "PRJ: $GIT_HOST ${GIT_HOST_SSH}:$GITLAB_ROOTGROUP/$GITLAB_SUBGROUP/$GITLAB_PROJECT"

#ssh免密： http://$GIT_HOST/-/profile/keys
#防止操作时的提示：Are you sure you want to continue connecting (yes/no/[fingerprint]
# git config --global core.sshCommand "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
:<<EOF
~/.gitconfig 类似如下
[core]
	sshCommand = ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
EOF

mkdir -p ./prjs/$GITLAB_PROJECT
pushd ./prjs/$GITLAB_PROJECT
  	git config --global user.email "wushifengcn@qq.com" ||true
  	git config --global user.name "wushifeng" ||true

	git init
	git remote add origin git@${GIT_HOST_SSH}:$GITLAB_ROOTGROUP/$GITLAB_SUBGROUP/$GITLAB_PROJECT.git
	echo "TCA Check" > ./README.md
	git add .
	git commit -m "Initial commit"
	git push -u origin master
popd

echo "project code repo init done"